#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <setjmp.h>

static sigjmp_buf               buf;
static volatile sig_atomic_t    canjmp;

void handler(int sig)
{
    if (canjmp == 0)
        return;
    /* ... */
    canjmp = 0;
    siglongjmp(buf, 1);
}

int main()
{
    signal(SIGINT, handler);
    if (!sigsetjmp(buf, 1))
        printf("starting\n");
    else
        printf("restarting\n");
    canjmp = 1;
    while (1) {
        sleep(1);
        printf("processing ...\n");
    }
    exit(0);
}
